package com.dragon.protoJo.bean.msg;


import lombok.Data;

import java.util.List;

@Data
public class UserDTO {

    String userId;
    String userName;
    //加入的群id
    List<String> groupIds;
    String devId;
    String token;
    String nickName = "nickName";
    PLATTYPE platform = PLATTYPE.WEB;
    private String sessionId;

    public enum PLATTYPE {
        WINDOWS, MAC, ANDROID, IOS, WEB, OTHER
    }
    public void setPlatform(int platform)
    {
        PLATTYPE[] values = PLATTYPE.values();
        for (int i = 0; i < values.length; i++)
        {
            if (values[i].ordinal() == platform)
            {
                this.platform = values[i];
            }
        }

    }

    @Override
    public String toString()
    {
        return "User{" +
                "uid='" + userId + '\'' +
                ", devId='" + devId + '\'' +
                ", token='" + token + '\'' +
                ", nickName='" + nickName + '\'' +
                ", platform=" + platform +
                ", groupIds =" + groupIds +
                '}';
    }

    public static UserDTO fromMsg(ProtoMsg.LoginRequest info)
    {
        UserDTO user = new UserDTO();
        user.userId = new String(info.getUid());
        user.devId = new String(info.getDeviceId());
        user.token = new String(info.getToken());
        user.setPlatform(info.getPlatform());
        return user;

    }
}
